package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.GoodsPublishDetail;
import com.zoshine.zzg.pojo.pojostatus.GoodsPublicStatus;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.GoodsPublishDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**内网商品库维护
 * @author 田沛凌
 * @time 2017/7/26 16:11
 */
@RestController
@RequestMapping(value = "innerGoods",method = RequestMethod.POST)
public class InnerGoodsController extends BaseController{
    private GoodsPublishDetailService goodsPublishDetailService;
    @Autowired
    public void setGoodsPublishDetailService(GoodsPublishDetailService goodsPublishDetailService) {
        this.goodsPublishDetailService = goodsPublishDetailService;
    }

    /**
     * 内网商品库显示
     * @param goodsPublishDetail；
     */
    @RequestMapping("/listGoods")
    @SuppressWarnings("unchecked")
    public BaseResponse listGoods(GoodsPublishDetail goodsPublishDetail){
        List<Long> prisonPower = super.getPrisonPower();
        List<Long> supplierPower = super.getSupplierPower();
        goodsPublishDetail.setPrisonPower(prisonPower);
        goodsPublishDetail.setSupplierPower(supplierPower);
        List<GoodsPublishDetail> list = goodsPublishDetailService.list(goodsPublishDetail);
        return new AppResponse(list);
    }

    /**
     * 内网商品库显示
     * @param goodsPublishDetail；
     */
    @RequestMapping("/pageGoods")
    @SuppressWarnings("unchecked")
    public BaseResponse pageGoods(GoodsPublishDetail goodsPublishDetail){
        List<Long> prisonPower = super.getPrisonPower();
        goodsPublishDetail.setPrisonPower(prisonPower);
        List<GoodsPublishDetail> list = goodsPublishDetailService.list(goodsPublishDetail);
        return new AppResponse(new PageInfo<>(list));
    }

    /**
     * 根据商品编号获取商品信息
     *
     * @param id 商品编号
     * @return 商品信息
     */
    @RequestMapping("/getGoods")
    public BaseResponse getGoods(Long id) {
        GoodsPublishDetail goodsPublishDetail = goodsPublishDetailService.get(id);
        return new AppResponse(goodsPublishDetail);
    }

    /**
     * 监仓机商品显示(上架商品)
     * @param goodsPublishDetail；
     */
    @RequestMapping("/listGoodsUp")
    @SuppressWarnings("unchecked")
    public BaseResponse listGoodsUp(GoodsPublishDetail goodsPublishDetail){
        List<Long> supplierPower = super.getSupplierPower();
        List<Long> prisonPower = super.getPrisonPower();
        goodsPublishDetail.setPrisonPower(prisonPower);
        goodsPublishDetail.setSupplierPower(supplierPower);
        goodsPublishDetail.setGoodsStatus(GoodsPublicStatus.PUBLISH.getValue());
        List<GoodsPublishDetail> list = goodsPublishDetailService.list(goodsPublishDetail);
        return new AppResponse(list);
    }
    /**
     * 商品上架
     * @param idStr (上架ID集合)
     */
    @RequestMapping("/upGoods")
    public BaseResponse upGoods(String idStr){
        goodsPublishDetailService.upGoods(idStr);
        return AppResponse.OK;
    }
    /**
     * 商品下架
     * @param idStr (下架ID集合)
     */
    @RequestMapping("/downGoods")
    public BaseResponse downGoods(String idStr){
        goodsPublishDetailService.downGoods(idStr);
        return AppResponse.OK;
    }

}
